Skip to content

Capture: a deadline per shot so a hung renderer can't hang the run - #61

Merged
tmashara merged 2 commits into
mainfrom
claude/issue-54-shot-deadline
Oct 29, 2026
Merged

tmashara merged 2 commits into
mainfrom
claude/issue-54-shot-deadline

Conversation

@tmashara

@tmashara tmashara commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

What

Each capture attempt in shoot() now races a 120s deadline. On expiry the page is closed and replaced with a fresh, prepare()d page in the same context, and the shot throws errors.TimeoutError("timeout after 120s at <step> on <side>"). transient() already retries TimeoutError, so it gets the existing retry-once, then the existing error path: an ERROR row, results.json, the report's errors list, exit 3.

  • src/capture.ts: a page-keyed step WeakMap, the same pattern as network. capture() sets it to load, before hook, settle or screenshot, so the error says where it stuck.
  • src/run.ts: the worker keeps its two pages in a mutable pages holder, so locate/masks/snapshot and the next job use the replacement page. A deadline hit in the before hook step throws a HookError instead, so a hook that may have half-run is never retried, as for a hook that throws.

Why

Only goto had a timeout. addStyleTag, every page.evaluate, the before hook and screenshot had none, and the in-page timer races can't fire while the renderer's main thread is wedged. One hung call blocked Promise.allSettled in the worker forever. Nothing was printed or written, and the process never exited.

Deviations from the issue

  • The page is replaced, not the context. Closing a page is enough to abandon its pending calls. Closing the right context would flush its routeFromHAR update: true recording, and a recreated context would overwrite that part file and lose the earlier shots' entries. It would also mean redoing storageState and the routes. The close is awaited because page.clock belongs to the context, so a page still closing would break the replacement's clock.install.
  • Env knob RENDERDIFF_SHOT_TIMEOUT (seconds, default 120; a missing, zero, negative or non-numeric value falls back to 120), not a config field. The regression test needs a short deadline. A config field would need validation, configHash and config-shape docs. It also gives a user with a very slow page a way to raise the limit, and it's documented in docs/how-it-works.md and the skill's Errors table.

Testing

  • New fixture tests/fixtures/pages/hang: a MutationObserver on <head> busy-loops on renderdiff's first injected <style>, so addStyleTag never returns. It's deterministic and needs no timers.
  • New visual test shot deadline in tests/visual/guardrails.test.ts. It runs /hang then /home at concurrency 1 with RENDERDIFF_SHOT_TIMEOUT=5 (headroom for /home on a loaded CI runner), and checks for exit 3, one error matching timeout after 5s at settle on left, and /home comparing identical on the same worker (which proves the replacement page works). A second test gives /menu a before hook that never resolves and checks for timeout after 2s at before hook on left with no retry (2 hits, one per side).
  • Red/green: on main the test fails with renderdiff timed out at the 60s harness limit. With the fix the two tests take about 15s.
  • npm run typecheck, npm run lint, npm run format:check, npm test (290/290) and npm run test:visual (329/329) all pass.

Fixes #54

🤖 Generated with Claude Code

tmashara and others added 2 commits October 29, 2026 16:44
One hung page call (an evaluate on a wedged renderer, a hook that never
resolves) blocked the worker forever: no row, no report, no exit. Each
capture attempt now races a 120s deadline (RENDERDIFF_SHOT_TIMEOUT
seconds). On expiry the page is closed and replaced in the same context,
and the shot throws a TimeoutError naming the step, which the existing
retry-once and error path handle.

Fixes #54

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… test deadline

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmashara
tmashara merged commit ec0fe19 into main Oct 29, 2026
3 checks passed
@tmashara
tmashara deleted the claude/issue-54-shot-deadline branch October 29, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deadline per shot so a hung renderer can't hang the run

1 participant